<?php
/**
 * Pertyler
 * Object Browser's Table's Objects Page
 *
 * @author	Emre Hasegeli <hasegeli@gmail.com>
 * @license	GNU General Public License v3
 */

namespace Pertyler;

require_once 'main.php';

if((empty($page->ParentTable)) OR (empty($page->ParentRow)) OR (empty($page->Table)))
	die;

$parentTable = Pertyler_Table::Select($page->ParentTable);

$parentRow = $parentTable->SelectRow($page->ParentRow);

$table = $parentRow->SelectTable($page->Table);

$treeView = new \KoolTreeView('treeView');

$treeView->imageFolder = $iconsFolder;

$treeView->showLines = true;

if($table->ConnectorTable())
{
	$link = new Link('ConnectorRow.php', 'body');

	$link->ParentTable = $table->id();

	foreach($table->SelectRowArray() AS $row)
	{
		$link->Row = $row->id();

		$treeView->Add('root',
				$row->id(),
				$link->Html($row),
				false,
				'help_page.gif');
	}
}
else
{
	$link = new Link('row.php', 'body');

	$link->ParentTable = $table->id();

	$treeNodesLink = new Link('ObjectBrowser_rowsObjects.php');

	$treeNodesLink->ParentTable = $table->id();

	foreach($table->SelectRowArray() AS $row)
	{
		$link->Row = $row->id();

		$treeNodesLink->Row = $row->id();

		if($row->VirtualRow())
			$treeView->Add('root',
					$row->id(),
					$link->Html($row),
					false,
					'contact.gif');
		else
			$treeView->Add('root',
					$row->id(),
					$link->Html($row),
					false,
					'help_page.gif',
					$treeNodesLink->Href());
	}
}

$treeView->isSubTree = true;

$treeView->width = '250px';

echo $treeView->Render();